<?php
require_once 'Sabai/Controller/ModelEntityDelete.php';

class Xigg_Admin_Plugin_Uninstall extends Sabai_Controller_ModelEntityDelete
{
    function Xigg_Admin_Plugin_Uninstall()
    {
        $url = array('base' => '/plugin');
        $options = array('successURL' => $url, 'errorURL' => $url);
        parent::Sabai_Controller_ModelEntityDelete('Plugin', 'id', $options);
    }

    function _onEntityDeleted(&$entity)
    {
        $plugin_manager =& $this->_locator->getService('PluginManager');
        $plugin_manager->dispatch('Uninstall', array(), $entity->get('name'));
        // reload plugins
        $plugin_manager->loadPlugins(true);
    }

    function _onDeleteEntity(&$entity, &$context)
    {
        $context->response->setVar('breadcrumb_current', _('Uninstall Plugin'));
        return true;
    }
}